﻿
// <copyright file="ControllablesConfigurationSection.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The controllables configuration section.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.ServiceProcess
{
    using System.Collections.Generic;
    using System.Configuration;
    using System.Xml;

    using SubhadraSolutions.Sharp.Utils.Contracts;
    using SubhadraSolutions.Sharp.Utils.Reflection;

    /// <summary>
    /// The controllables configuration section.
    /// </summary>
    public class ControllablesConfigurationSection : ConfigurationSection
    {
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="ControllablesConfigurationSection"/> class.
        /// </summary>
        public ControllablesConfigurationSection()
        {
            this.Controllables = new List<IControllable>();
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the controllables.
        /// </summary>
        public List<IControllable> Controllables { get; private set; }

        #endregion Public Properties

        #region Methods

        /// <summary>
        /// The deserialize section.
        /// </summary>
        /// <param name="reader">
        /// The reader.
        /// </param>
        protected override void DeserializeSection(XmlReader reader)
        {
            var doc = new XmlDocument();
            doc.Load(reader);
            ComponentBuilder.PopulateList(this.Controllables, doc.ChildNodes[0].ChildNodes[0]);
        }

        #endregion Methods
    }
}